<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>reduce</title>
  </head>

  <body>
    <script>
      const urlObj = location.search
        .slice(1)
        .split("&")
        .filter(Boolean)
        .reduce(function (obj, cur) {
          const arr = cur.split("=");
          if (arr.length != 2) {
            return obj;
          }
          obj[decodeURIComponent(arr[0])] = decodeURIComponent(arr[1]);
          return obj;
        }, {});

      function getQueryString(key) {
        return urlObj[key];
      }

      console.log("words:", getQueryString("words")); // vue
      console.log("wordss:", getQueryString("wordss")); // null
    </script>
  </body>
</html>
